<!doctype html>
<html>

<head>
    <title>Socket.IO chat</title>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="/socket.io/socket.io.js"></script>
</head>

<body>
    <h1>后端向前端单向传消息</h1>
    <ul id="messages"></ul>
</body>
<script>
    var socket = io();
    //发送昵称给后端
    let name = 'boy';
    socket.emit("join", name);
    //接收到服务器发来的message事件
    socket.on("message", function (msg) {
        $('#messages').append($('<li>').text(msg));
    })

</script>

</html>